"use strict";
/* Controllers */
app.controller("hdfsTableListController", ['$scope', '$location', '$rootScope', '$routeParams', 'hdfsTableListService', function ($scope, $location, $rootScope, $routeParams, hdfsTableListService) {

    var vm = $scope.vm = {};


    vm.p = {};
    vm.result = {};

    vm.p.clusterName = $routeParams.cluster;
    vm.p.dbName = $routeParams.db; //  获取应用模块的名称

    //vm.p.subBillNo = 0;
    //vm.p.startTime = getNowFormatDate();
    //vm.p.endTime =  getNowFormatDate();
    //vm.p.pageInfo = {pageSize:30, pageNum:1};


    //vm.select = {};
    //$scope.change_cluster = function() {
    //    var vm = $scope.vm;
    //    $location.path('/detail/'+vm.select.cluster + "/cluster/" + vm.select.cluster);
    //};
    //vm.search = {};
    //vm.search.ts = 0;
    //$scope.change_search_time = function() {
    //    var vm = $scope.vm;
    //    var curr = new Date();
    //    curr.add("s", - vm.search.ts); //昨天
    //    vm.search.time = curr.format("yyyy-MM-dd hh:mm:ss");
    //};
    //$scope.change_search_time();// 初始化vm.search.time

    var errorFn = function (result) {
        alert(result);
    };

    $scope.searchHdfsTable = function (t) {
        var vm = $scope.vm;
        $scope.listCostReport();
    };
    $scope.listHdfsTable = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        vm.p.param = {clusterName: vm.p.clusterName, dbName: vm.p.dbName};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        hdfsTableListService.listHdfsTable(vm.p.param, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listHdfsTable();
    };
    $scope.initializeController();
}]);


/* Services */
app.service('hdfsTableListService', ['ajaxService', function (ajaxService) {

    this.listHdfsTable = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/hdfs_table/listHdfsTable.do", successFunction, errorFunction);
    };

    this.deleteHdfsTable = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/hdfs_table/deleteHdfsTable.do", successFunction, errorFunction);
    };
}]);

function tableIDOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/hdfs_table_detail/', value, '" target="_blank">', "<u>管理</u>" , '</a>'
    ].join('');
}
